<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var sum = 0;
        var index = 0;
        var arr = ["a", "b", "c", "d", "d", "f", "c", "d"];
        function findall(arr) {
            index = arr.indexOf("d");
            while (index != -1) {
                document.write(index + "\t");
                index = arr.indexOf("d", index + 1);
            }
        }
        function count(arr) {
            index = arr.indexOf("d");
            while (index != -1) {
                sum++;
                index = arr.indexOf("d", index + 1);
            }
            document.write("<br>" + sum);
        }
        findall(arr);
        count(arr);
    </script>
</body>
</html>